package com.dream.model.order;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.collections.CollectionUtils;
import org.hibernate.annotations.Type;

import com.dream.model.app.AppOrg;
import com.dream.model.base.AppModelBase;

@Entity
@Table(name="t_ord_customer")
public class OrderCustomer extends AppModelBase implements Serializable {


	/**
	 * 
	 */
	private static final long serialVersionUID = 8244451160512441504L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private String id ;
	
	@Column(name="type")
	private Long type;
	
	@Column(name="org_id")
	private Long orgId;
	
	@Column(name="name")
	private String name;

	@Column(name="mobile")
	private String mobile;
	
	@Column(name="phone")
	private String phone;
	
	@Column(name="gender")
	private Long gender;
	
	@Column(name="email")
	private String email;
	
	@Column(name="zip")
	private String zip;	
	
	@Column(name="address")
	private String address;	
	
	@Column(name="comments")
	private String comments;			
	
	@Column(name="deleted")
	@Type(type = "org.hibernate.type.NumericBooleanType")
	private Boolean deleted = false;
	
	@Transient
	private AppOrg firstOrg;
	
	@Transient
	private AppOrg secondOrg;
	
	public void initOrgs(List<AppOrg> li){
		
		if(CollectionUtils.isNotEmpty(li)){
			for(AppOrg org :li){
				if(org.getLevel().equals(1)){firstOrg = org;}
				if(org.getLevel().equals(2)){secondOrg = org;}
			}
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Long getType() {
		return type;
	}

	public void setType(Long type) {
		this.type = type;
	}

	public Long getOrgId() {
		return orgId;
	}

	public void setOrgId(Long orgId) {
		this.orgId = orgId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Long getGender() {
		return gender;
	}

	public void setGender(Long gender) {
		this.gender = gender;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public Boolean getDeleted() {
		return deleted;
	}

	public void setDeleted(Boolean deleted) {
		this.deleted = deleted;
	}
	

	public AppOrg getFirstOrg() {
		return firstOrg;
	}

	public void setFirstOrg(AppOrg firstOrg) {
		this.firstOrg = firstOrg;
	}

	public AppOrg getSecondOrg() {
		return secondOrg;
	}

	public void setSecondOrg(AppOrg secondOrg) {
		this.secondOrg = secondOrg;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OrderCustomer other = (OrderCustomer) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
}
